package com.zf.shuashua.helper;

import android.app.Dialog;
import android.content.Context;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.zf.shuashua.R;

public class LoadDialogManager {

    private Dialog mDialog;

    private static class SingletonHolder {
        private static final LoadDialogManager INSTANCE = new LoadDialogManager();
    }

    public static LoadDialogManager getInstance() {
        return SingletonHolder.INSTANCE;
    }

    private LoadDialogManager() {
    }

    public void show(Context context) {
        if (mDialog != null) {
            dismiss();
        }
        mDialog = new Dialog(context, R.style.DialogStyle);
        ImageView imageView = new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.CENTER);
        Glide.with(context).load(R.drawable.login_loading).into(imageView);
        RelativeLayout relativeLayout = new RelativeLayout(context);
        relativeLayout.addView(imageView);
        mDialog.setContentView(relativeLayout);
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setCancelable(false);
        mDialog.show();
    }

    public void dismiss() {
        if (mDialog != null) {
            mDialog.dismiss();
            mDialog = null;
        }
    }

}